|
|
 |
|
|
|
|
ByVal eye_y As Single, ByVal eye_z As Single) As Long
Dim light As LightSource
Dim Lx As Single
Dim Ly As Single
Dim Lz As Single
Dim L_len As Single
Dim Nx As Single
Dim Ny As Single
Dim Nz As Single
Dim NdotL As Single
Dim R As Integer
Dim G As Integer
Dim B As Integer
Dim distance_factor As Single
Dim diffuse_factor As Single
Dim Vx As Single
Dim Vy As Single
Dim Vz As Single
Dim V_len As Single
Dim Rx As Single
Dim Ry As Single
Dim Rz As Single
Dim RdotV As Single
Dim specular_factor As Single
' Find the unit surface normal. It is the
' same for all the light sources. UnitNormalVector Nx, Ny, Nz
For Each light In light_sources
' **********************
' * Diffuse Reflection * ' **************************
' Find the unit vector pointing towards the light. Lx = light.X - Points(1).coord(1)
Ly = light.Y - Points(1).coord(2)
Lz = light.Z - Points(1).coord(3)
L_len = Sqr(Lx * Lx + Ly * Ly + Lz * Lz)
Lx = Lx / L_len
Ly = Ly / L_len
Lz = Lz / L_len
' See how intense to make the color. NdotL = Nx * Lx + Ny * Ly + Nz * Lz
' The light does not hit the top of the
' surface if NdotL <= 0. If NdotL > 0 Then
distance_factor = (light.Rmin + light.Kdist) / _
(L_len + light.Kdist)
diffuse_factor = NdotL * distance_factor
R = R + light.Ir * DiffuseKr * diffuse_factor |
|
|
|
|
|